var util = require('../../utils/util.js')
var app = getApp();
var md5 = require('../md5.js');
Page({
  data: {
    currentTab: 0,
    "value": "",   // 文本的内容
    "placeholder": "请输入文本",
    "maxlength": -1,  // 最大输入长度，设置为 -1 的时候不限制最大长度
    "focus": true,
    "auto-height": true,  // 是否自动增高，设置auto-height时，style.height不生效
    "adjust-position": true, // 键盘弹起时，是否自动上推页面
  },
  onLoad: function (options) {
    var that = this
    // 页面初始化 options为页面跳转所带来的参数
    //设置语言0:中文，1：英文
    var setlanguage = wx.getStorageSync('setlanguage')
    if ((wx.getStorageSync('setlanguage') || !"".trim() == wx.getStorageSync('setlanguage'))) {
      this.setData({
        setlanguage: wx.getStorageSync('setlanguage')
      })
      if (setlanguage == 1) {
        wx.setNavigationBarTitle({
          title: 'My notes'
        })
      } else {
        wx.setNavigationBarTitle({
          title: '我的笔记'
        })
      }
    } else {
      wx.setStorageSync('setlanguage', 0);
      this.setData({
        setlanguage: 0
      })
    }
    var attendeeid = options.attendeeid
    var notecontent = options.notecontent
    this.setData({
      attendeeid: attendeeid
    })
    this.setData({
      notecontent: notecontent
    })

  },
  onPullDownRefresh: function(){
    wx.stopPullDownRefresh({
      complete: (res) => {},
    });
  },
  //底部导航跳转
  toAiIndex: function () {
    util.toAiIndex()
  },
  toContactsIng: function () {
    util.toContactsIng()
  },
  toProductRevision: function () {
    util.toProductRevision()
  },
  toMy: function () {
    util.toMy()
  },
  toBadge: function () {
    util.toBadge()
  },
  getVal: function (e) {
    var mesg = e.detail.value
    this.setData({
      notecontent: mesg
    })
  },
  submit: function () {
    var that = this
    var attendeeid = that.data.attendeeid
    var notecontent = that.data.notecontent
    //调用pico更新笔记
    var exhibitionid = wx.getStorageSync('exhibitionid')
    var u = wx.getStorageSync('u')
    var timestamp = Date.parse(new Date());
    timestamp = timestamp / 1000;
    var url = app.globalData.picoaddress + '/attendee/contacts/updatenote'
    var k = {}
    k["v"] = '1.0.0'
    k["client"] = 'ios'
    k["timestamp"] = timestamp
    k["lan"] = 'cn'
    k["exhibitionid"] = exhibitionid
    k["contactid"] = attendeeid
    k["content"] = notecontent
    k["source"] ='0'
    k["u"] = u
    var sign = app.globalData.picotoken + 'clientios' + 'contactid' + attendeeid + 'content' + notecontent + 'exhibitionid' + exhibitionid + 'source0timestamp' + timestamp + app.globalData.picotoken
    console.log(sign)
    var curb64 = md5.zhMD5(sign)
    console.log(curb64)
    k["sign"] = curb64
    wx.request({
      header: {
        'content-type': 'application/x-www-form-urlencoded',
      },
      url: url,
      method: 'post',
      data: k,
      success(res) {
        wx.navigateTo({
          url: '../pageDetail/pageDetails?attendeeid=' + attendeeid,
        })

      }, fail: res => {
        console.log(res, "error")
      }

    })
  },
})